package com.dingli.service.impl;

import com.dingli.framework.entity.Trainmember;
import com.dingli.framework.entity.Undertake;
import com.dingli.framework.mapper.TrainmemberMapper;
import com.dingli.framework.util.Response;
import com.dingli.service.ITrainmemberService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public class TrainmemberService implements ITrainmemberService {

    @Autowired
    private TrainmemberMapper trainmemberMapper;

    @Override
    public Response<PageInfo<Trainmember>> TRselectList(String search, Integer pageNum, Integer pageSize) {
        if (pageNum == null) {
            pageNum = 1;
        }
        if (pageSize == null) {
            pageSize = 10;
        }
        PageHelper.startPage(pageNum, pageSize);
        PageInfo<Trainmember> info = new PageInfo<>(trainmemberMapper.TRselectList(search));
        return new Response<>(200, "success", info);
    }

    @Override
    public Response<List<Trainmember>> TRselectAll(Long tbId) {
        return new Response<>(200, "success", trainmemberMapper.TRselectAll(tbId));
    }

    @Override
    public Response<Object> TRupdateState(String tbId) {
        return new Response<>(200, "success", trainmemberMapper.TRupdateState(tbId));
    }

    @Override
    public Response<Object> TRupdate(String tbId) {
        return new Response<>(200, "success", trainmemberMapper.TRupdate(tbId));
    }

    @Override
    public Response<List<Trainmember>> TRselect(String tbId) {
        return new Response<>(200, "success", trainmemberMapper.TRselect(tbId));
    }

    @Override
    public Response<Long> TRinsert(Trainmember trainmember) {
        int count = trainmemberMapper.TRinsert(trainmember);
        if (count > 0) {
            return new Response(200, "success", trainmember.getTbId());
        } else {
            return new Response<>(500, "failed");
        }
    }

    @Override
    public Response<Object> TRupdateById(Trainmember trainmember) {
        int count = trainmemberMapper.TRupdateById(trainmember);
        if (count > 0) {
            return new Response<>(200, "success");
        } else {
            return new Response<>(500, "failed");
        }
    }

    @Override
    public Response<Object> TRdeleteById(Long tbId) {
        int count = trainmemberMapper.TRdeleteById(tbId);
        if (count > 0) {
            return new Response<>(200, "success");
        } else {
            return new Response<>(500, "failed");
        }
    }
}